
// SystemPrint.log(app.getAllApp())
var APP_NAME_demo = '皮皮虾'
var PACK_NAME_demo = 'com.sup.android.explore'

function skip_主界面的弹窗_demo() {

}

function skip_任务中心的弹窗_demo() {

}

function back2center_demo() {
    // if (!backUntilFindView(() => ocrText('日常任务', '金币:', '抵用金:', '点就领'))) {
    //     enter_任务中心_demo(true)
    // }
    array.forEach(element => {
        // Ddddd
    });
}


function move2顶部() {
    move2Top(1, 300, '现金收益', '赚赚卡', '活动收益')
}

// 启动任务
function start_app_demo() {
    var isuccess = startApp(PACK_NAME_demo)
    if (!isuccess) {
        return false
    }

    // 跳过首页广告
    expectView(() => {
        return ocrTextMoreInRegion(0, 0.88, 1, 1, '首页')
    }, (times) => {
        skip_主界面的弹窗_demo()

        if (times > 3) {
            agentOrHidback()
            sleep.millisecond(500)
            // todo
        }
        sleep.millisecond(500)
    }, (findView) => {
        // agentOrHidClick(findView)
    }, null, 3)

    return true
}

// 进入任务中心
function enter_任务中心_demo(iskip) {
    log('进入任务中心')

    if (iskip == undefined) iskip = false

    // 进入任务中心
    expectView(() => {
        return ocrTextMoreInRegion(0, 0.88, 1, 1, '现金')
    }, (times) => {
        skip_主界面的弹窗_demo()

        sleep.millisecond(500)
        SystemPrint.warn('未找到主界面期望标志位')
    }, (findView, stepTimes) => {
        if (stepTimes == 1) {
            skip_主界面的弹窗_demo()
        }
        agentOrHidClick(findView)
    }, () => {
        // 失败后的方案 或者其它方案进入
        clickOffectY(3 / 8, 1, 60)
    }, 6)


    if (!iskip) {
        // 期望标志位
        expectView(() => {
            return ocrText('现金收益')
        }, (times) => {
            skip_任务中心的弹窗_demo()

            if (times > 3) {
                agentOrHidback()
                sleep.millisecond(500)
                // todo 未找到后 返回怎么做
            }
            sleep.millisecond(500)
            SystemPrint.warn('未找到任务界面期望标志位')
        }, (findView) => {
            // agentOrHidClick(findView)
        }, null, 3)
    }
}


function open_签到_demo() {
    log('签到')
    if (hasExcuteFunc('open_签到_demo')) {
        logSleep('签到已经完成')
        return
    }

    if (getExcuteFuncTimes('open_签到_demo') <= 1) {
        agentOrHidClick(ocrWaitForText('立即领取+', '立即领取'))
        watchGG_皮皮虾独享()
    } else {
        skip_任务中心的弹窗_demo()
    }

    addExcuteFuncTimes('open_签到_demo')
}

function open_开宝箱_demo() {
    log('开宝箱')
    skip_任务中心的弹窗_demo()

    agentOrHidClick(ocrText('开宝箱得金币'), 1, () => {
        watchGG_多次看广告(ocrTextMoreInRegion(0, 0.5, 1, 0.8, '看视频', '看广告'))
    })
}

function watch_看广告_demo() {
    log('看视频')
    if (hasExcuteFunc('watch_看广告_demo')) {
        return
    }
    skip_任务中心的弹窗_demo()

    move2顶部()
    // 只执行一次
    moveUp2FindWidTxtMore((findView) => {
        watchGG_多次看广告(findView)
        setExcuteFunc('watch_看广告_demo')
    }, '看广告赚金币', '看视频賺', '看视频')
}

// 进行浏览任务
function start_浏览任务_demo() {
    log('浏览任务')
    if (!start_app_demo()) {
        return
    }

    skip_主界面的弹窗_demo()
}


function start_收集金币_demo() {
    log('开始收集金币')
    if (!isAllow允许登录(PACK_NAME_demo)) {
        if (getExcuteFuncTimes('start_收集金币_demo') == 0) {

            printwarn('xxx启动失败或被屏蔽')
            sleep.second(10)

            addExcuteFuncTimes('start_收集金币_demo')
        }
        return
    }
    currentAppPackName = PACK_NAME_demo
    // closeApp(PACK_NAME_demo)

    if (!start_app_demo()) {
        return
    }

    addExcuteFuncTimes('start_收集金币_demo')

    enter_任务中心_demo()

    open_签到_demo()

    watch_看广告_demo()

    open_开宝箱_demo()

    stopAllApp()
    // closeApp(PACK_NAME_demo)
}